package cn.ydt.ydt.shopping.webapi.mapper;


import cn.ydt.ydt.pojo.shopping.dto.AddVegetableDTO;
import cn.ydt.ydt.pojo.shopping.dto.SimpleVegetableDTO;
import cn.ydt.ydt.pojo.shopping.model.Vegetable;
import cn.ydt.ydt.pojo.shopping.model.VegetableCart;
import cn.ydt.ydt.pojo.shopping.model.VegetableOrder;
import cn.ydt.ydt.pojo.shopping.model.VegetableOrderCart;
import cn.ydt.ydt.pojo.shopping.vo.SimpleVegetableVO;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@SpringBootTest
public class testVegetable {

    @Autowired
    IVegetableMapper vegetableMapper;

    @Test
    @Sql({"classpath:truncate_vegetable.sql","classpath:insert_vegetable.sql"})
    void testGetVegetableBySort(){
        String sort = "蔬菜";
        List<SimpleVegetableVO> list = vegetableMapper.getVegetableBySort(sort);
        log.info("查询的菜品列表:{}",list.toString());
    }

    //测试添加购物车
    @Test
    void addVegetableCart(){
        VegetableCart vegetableCart = new VegetableCart();
        vegetableCart.setVegetableId(2L);
        vegetableCart.setCartCount(5);
        LocalDateTime date  = LocalDateTime.now();
        vegetableCart.setCreateTime(date);
        vegetableCart.setModifyTime(date);
        vegetableCart.setUserId(1L);
        Assertions.assertEquals(1,vegetableMapper.addVegetableCart(vegetableCart));
    }

    //测试删除购物车
    @Test
    void testDelVegetableCart(){
        Long cartId = 2L;
        vegetableMapper.delVegetableCart(cartId);
    }

    //测试根据id查询购物车
    @Test
    void testgetCartById(){
        Long cartId = 5L;
        VegetableCart cart = vegetableMapper.getCartByCartId(cartId);
        log.info("cart:{}",cart);
    }

    //测试新增订单功能
    @Test
    void testAddOrder(){
        VegetableOrder vegetableOrder = new VegetableOrder();
        vegetableOrder.setUserId(1L);
        vegetableOrder.setIsComplete((byte)0);
        LocalDateTime dateTime = LocalDateTime.now();
        vegetableOrder.setGmtCreate(dateTime);
        vegetableOrder.setGmtModified(dateTime);
        vegetableMapper.addVegetableOrder(vegetableOrder);
    }

    //测试添加购物车订单关系
    @Test
    void testOrderCart(){
        VegetableOrderCart orderCart = new VegetableOrderCart();
        orderCart.setVegetableCartId(1L);
        orderCart.setVegetableOrderId(1L);
        LocalDateTime dateTime = LocalDateTime.now();
        orderCart.setCreateTime(dateTime);
        orderCart.setModifyTime(dateTime);
        vegetableMapper.addOrderCart(orderCart);
    }

    //测试完成订单
    @Test
    void testOrderComplete(){
        Long orderId = 1L;
        vegetableMapper.updateOrderComplete(orderId);
    }

    //测试根据用户id查询订单列表
    @Test
    void testgetOrderByUserId(){
        Long userId = 1L;
        List<VegetableOrder> list = vegetableMapper.getOrderByUserId(userId);
        log.info("list:"+list.toString());
    }

    //根据订单id查询购物车订单对应关系
    @Test
    void testgetOrderCartByOrderId(){
        Long orderId = 5L;
        List<VegetableOrderCart> list = vegetableMapper.getOrderCartByOrderId(orderId);
        log.info("list:",list.toString());
    }

    //查询所有菜品
    @Test
    void testVegetableAll(){
        List<Vegetable> list = vegetableMapper.getAllVegetableList();
        log.info("list:",list.toString());
    }

    //添加菜名
    @Test
    void testAddVegetable(){
        Vegetable vegetable = new Vegetable();
        vegetable.setVegetableName("榴莲");
        vegetable.setVegetableImage("aa.jpg");
        vegetable.setVegetableSort("水果");
        vegetable.setVegetablePrice(50.00);
        vegetable.setVegetableMax(3);
        vegetable.setVegetableStock(30);
        vegetable.setCommunityId(1L);
        vegetableMapper.addVegetable(vegetable);
    }

    //测试根据id查询菜品
    @Test
    void testGetVegetableById(){
        Long vegetableId = 1L;
        Vegetable vegetable = vegetableMapper.getVegetableById(vegetableId);
        log.info("结果：{}",vegetable.toString());
    }

    //测试根据用户id查询购物车id列表
    @Test
    void testGetCartByUserId(){
        Long userId = 1L;
        List<VegetableCart> cartList = vegetableMapper.getCartListByUserId(userId);
        log.info("购物车列表为：{}",cartList);
    }
}
